const webpack = require("webpack");
const ora = require("ora");
const chalk = require("chalk");
const WebpackConfig = require("../config/webpack.prod.config");

process.env.NODE_ENV = "production";
process.env.BABEL_ENV = "production";
//启动动画
// const spinner = ora("building...");
// spinner.start();

webpack(WebpackConfig, function(err, stats) {
  //停止动画
  // spinner.stop();
  if (err) {
    chalk.red(err);
    throw err;
    // process.exit();
  }
  process.stdout.write(
    stats.toString({
      colors: true,
      modules: false,
      children: false,
      chunks: false,
      chunkModules: false
    }) + "\n\n"
  );
  console.log(chalk.cyan("🍺  打包完成.\n"));
  console.log(
    chalk.yellow(
      "  Tip: built files are meant to be served over an HTTP server.\n" +
        "  Opening index.html over file:// won't work.\n"
    )
  );
  process.exit();
});
